<template>
  <div></div>
</template>
<script>
import { card_consult_add } from "@/api/service";
import { get_role } from "@/api/role";
import { subscribe_url } from "@/utils/const";

export default {
  name: "CardConsult",
  data() {
    return {
      agency_openid: this.$route.query.openid,
      openid: "",
    };
  },
  methods: {
    CardConsultAdd(data) {
      card_consult_add(data)
        .then((res) => {
          console.log(res);
          if (res) {
            if ("status_code" in res.data && res.data.status_code == "401") {
              this.$toast(res.data.message);
            }
            const openid = localStorage.getItem("openid");
            get_role(openid)
              .then((res) => {
                console.log(res);
                if (!res.subscribe) {
                  console.log(subscribe_url);
                  window.location.href = subscribe_url;
                } else {
                  this.$router.replace("/my_card_list");
                }
              })
              .catch((error) => {
                console.log(error);
                this.$router.replace("/my_card_list");
              });
          }
        })
        .catch((error) => {
          console.log(error);
        });
    },
  },
  created() {
    this.agency_openid = this.$route.query.openid;
    console.log(this.agency_openid);
    this.openid = localStorage.getItem("openid");
    const data = {
      openid: this.openid,
      agency_openid: this.agency_openid,
    };
    this.CardConsultAdd(data);
  },
};
</script>
